﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.IO;
using System.Globalization;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CrystalDecisions.CrystalReports.Engine;

namespace StockMentor
{
    public partial class frmReport : Form
    {
        private string sPath;
        private DataSet dsResult;
        Hashtable hParam = null;
        public frmReport(string sPath, DataSet dsResult)
        {
            InitializeComponent();
            this.sPath = sPath;
            this.dsResult = dsResult;
        }

        public frmReport(string sPath, DataSet dsResult, Hashtable hParam)
        {
            InitializeComponent();
            this.sPath = sPath;
            this.dsResult = dsResult;
            this.hParam = hParam;
        }

        private void frmReport_Load(object sender, EventArgs e)
        {
            creazaRaport();
        }


        private void creazaRaport()
        {
            ReportDocument rptDoc = new ReportDocument();
            rptDoc.Load(sPath);
            rptDoc.SetDataSource(dsResult.Tables[1]);
            try
            {
                if (hParam != null)
                {
                    IDictionaryEnumerator dic_enum = hParam.GetEnumerator();
                    dic_enum.Reset();

                    while (dic_enum.MoveNext())
                    {
                        DictionaryEntry entry = dic_enum.Entry;
                        rptDoc.SetParameterValue(entry.Key.ToString(), entry.Value.ToString());
                    }
                }
            }
            catch
            {
            }
            //rptDoc.PrintOptions.PaperOrientation = CrystalDecisions.Shared.PaperOrientation.Landscape;
                            
            crystalReportRecep.DisplayToolbar = true;
            crystalReportRecep.ShowCloseButton = true;
            crystalReportRecep.ReportSource = rptDoc;
            crystalReportRecep.Refresh(); 
       
        }
    }
}
